﻿@using System.Data
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
    DataTable table = ViewData["sort"] as DataTable;
}
<style>
    * {
        overflow: auto;
    }
</style>
<div class="searchpanel">
    <div class="seatchtool">
        <div class="operationtool">
     
            <a id="add">增加</a>
         
        </div>
        <div class="operationsearch">

        </div>
    </div>
</div>
<table class="datatable">
    <tr>
     
        <th width="200">商品分类</th>
        <th width="200">分类描述</th>
        <th width="200">图片</th>
        <th width="200">序号</th>
        <th width="300">操作</th>
        <th></th>
    </tr>
    <tbody id="list">
        @{
            if (table.Rows.Count>0)
            {
                foreach (DataRow row in table.Rows)
                {
                    <tr>
                        <td>@row["Name"]</td>
                        <td>@row["Des"]</td>
                        <td><img src="@row["Img"]" width="200" height="200"/></td>
                        <td>@row["Order"]</td>
                        <td>
                            <a class="ope_bt" onclick="del(@row["Id"])">删除</a>&nbsp;
                            <a class="ope_bt" onclick="edit(@row["Id"])">修改</a>
                        </td>
                        <td></td>
                    </tr>
                }
            }

        }
    </tbody>


</table>


<script>
        //添加
        $("#add").click(function () {
            location.href = "@Url.Action("Window",new {id=0})";
        });

//修改
        function edit(id) {
            $("#list input[type=checkbox]").each(function() {
                if ($(this).attr("checked")) {
                    id = $(this).val();
                    return false;
                }
            });
            if (id == 0) {
                alert("请选择要修改的数据！");
            } else {
                location.href = "@Url.Action("Window")" + "/" + id;
            }
        }

    function del(id) {
        if (confirm("确定删除数据吗？")) {

            $.post("@Url.Action("DelSort")", { id: id }, function (row) {
                if (row > 0) {
                    location.reload();
                } else {
                    alert("删除失败！");
                }
            });
    }
    }
</script>

